import 'package:json_annotation/json_annotation.dart';

import 'read_entity.dart';

part 'socket_chat_entity.g.dart';

@JsonSerializable()
class SocketChatEntity {
  /// 消息客户端ID
  /// 用作消息的唯一标识，由客户端生成
  @JsonKey(name: "msg_client_id")
  String? msgClientId;

  @JsonKey(name: "msg_id")
  String? msgId;

  /// 是否是自己发送的消息
  @JsonKey(name: "is_myself")
  bool? isMyself;

  /// 消息内容
  @JsonKey(name: "status_tips")
  String? statusTips;

  /// 消息已读时间
  @JsonKey(name: "read_timestamp")
  String? readTimestamp;

  /// 消息状态
  /// 1: 发送中
  /// 2: 已发送
  /// 3: 已送达
  /// 4: 已读
  @JsonKey(name: "status")
  int? status;

  /// 消息
  @JsonKey(name: "info")
  String? info;

  @JsonKey(name: "receivers_all", defaultValue: [])
  List<ReadEntity>? receiversAll;

  @JsonKey(name: "receivers_read", defaultValue: [])
  List<ReadEntity>? receiversRead;

  SocketChatEntity({
    this.msgClientId,
    this.msgId,
    this.isMyself,
    this.statusTips,
    this.readTimestamp,
    this.status,
    this.info,
    this.receiversAll,
    this.receiversRead,
  });

  /// 从JSON映射创建消息实体对象
  factory SocketChatEntity.fromJson(Map<String, dynamic> json) => _$SocketChatEntityFromJson(json);

  /// 将消息实体对象转换为JSON映射
  Map<String, dynamic> toJson() => _$SocketChatEntityToJson(this);
}
